home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interplay's Learn to Program Basic (Review Copy)
/
Learn to Program Basic Review Copy (Interplay)(June 23, 1998).ISO
/
pc
/
ltpbasic
/
projects
/
haunted.bas
< prev
next >
Wrap
BASIC Source File
|
1998-02-21
|
3KB
|
164 lines
Rem Haunted House
Rem Shooting Gallery
Rem See the bottom of this program
Rem for ideas on things you can
Rem change.
cls
Rem Define variables that will
Rem be used later in the program.
Rem You can play with these values
Rem and see what happens.
Delay = 5000
Score = 0
myBackground$ = "Castle"
emptyColor = 95
fullColor = 167
shotSize = 45
Rem Load the sounds we'll use
shotSnd = LoadSound("LAZER2")
Rem Choose from a list of random sounds
Rem that we play when monster appears
numPopupSnds = 4
Dim popupSnd(numPopupSnds)
popupSnd(1) = LoadSound("LaughEvl")
popupSnd(2) = LoadSound("Stomach")
popupSnd(3) = LoadSound("Squawk1")
popupSnd(4) = LoadSound("Digrdont")
Rem Choose from a list of random sounds
Rem that we sometimes play when a
Rem creature gets shot
numOtherSnds = 3
Dim otherSnd(numOtherSnds)
otherSnd(1) = LoadSound("Scream")
otherSnd(2) = LoadSound("DuckDth")
otherSnd(3) = LoadSound("Gloop")
Rem First set up an array to hold
Rem the X/Y coordinates of all the
Rem windows in the haunted house...
Dim Target(10,2)
Rem ...Then read the X/Y coordinates
Rem into that array.
For t = 1 to 10
Read Target(t,1)
Read Target(t,2)
next t
data 37,17,255,5,36,100,112,98,180,98
data 255,79,36,170,111,184,179,184,255,143
Rem Set up the screen.
Background myBackground$
bandit = LoadSprite("bandits")
SetSprite bandit to -100,-100
Rem OK, now we've set up the things
Rem that we only need to set up once
Rem at the beginning. Now let's
Rem start a loop and begin the game
Rem itself.
while 1
Rem Pick a random window
Rem and put in a creature
window = random(1,9)
x1 = target(window,1)
y1 = target(window,2)
x2 = x1+31
y2 = y1+31
SetSprite bandit frame random(0,4)
SetSprite bandit to x1,y1
PlaySound(popupSnd(Random(1,numPopupSnds)))
Rem Draw timer bar
Color emptyColor
FillRect 0,226 to 319,239
Position 0,14
Print "Score:";score;
Color 21
Rem Set up for this bullet
hit = 0
timestart = timer()
timeend = timestart + delay
curtime = timer()
Rem Main Loop
while hit = 0 and curtime < timeend
Rem Update the timer bar...
curtime = timer()
fraction = curtime - timestart
fraction = fraction / delay
fraction = 1.0 - fraction
Color fullColor
FillRect 320*fraction,226 to 319,239
Color 21
Rem Check if we've "fired"
Rem our gun at the
Rem creature
if ClickRect(x1,y1 to x2,y2) then
gosub GunShot
Score = Score + 1
Background myBackground$
Delay = Delay - 25
hit = 1
Rem see if we should play one of
Rem our "other" sounds
If Random(1,100) < 20 Then
PlaySound(otherSnd(Random(1,numOtherSnds)))
Endif
endif
wend
Rem Hit is 0 when the timer bar counts down to 0 - End the game
if hit = 0 then
HideSprite bandit
Cls
Print "Game Over!"
Sound "Headshke"
Print
Print "You were able to get ";score;" monsters."
Sleep 30 ' wait for sound to end
end
endif
wend
end
Rem A successful hit!
Rem do a "gunshot" effect
GunShot:
PlaySound(shotSnd)
x3 = x1 + x2
x3 = x3 / 2
y3 = y1 + y2
y3 = y3 / 2
for z = 1 to shotSize
Circle x3,y3,z
Color random(0,235)
next z
color 31
return
Rem Ideas for changes:
Rem - Lose 1 point for a miss
Rem - Gain 2 points for a hit
Rem - Change the sounds
Rem - Put in a "smart bomb" if
Rem you hit the space bar, for
Rem an automatic hit
Rem - Add "levels" to the game, so
Rem every 10 points you go up
Rem a level and the game speeds
Rem up a little
Rem - Or, when you go up a level,
Rem make an additional monster
Rem appear